<script setup lang='ts'>
  import { onMounted, reactive } from 'vue';
  import { ChallengeApi } from '@/api/controller'
  import { getPlayEndTime, getDateArray, getTimestamp, getHMMSS } from '@/utils'
  import { Toastloading } from '@/utils/public';
  import xmDatePicker from '@/components/xmDatePicker/index.vue';
  import Pagination from "@/components/Pagination/index.vue";
  import serachUserid from '@/components/serachUserid/index.vue';
  const action = reactive({
    total:0,
    list:[] as Array<any>,
    SessionList:[] as Array<any>,
    timeObj:getPlayEndTime(getDateArray('ymd'))
  })
  const listQuery = reactive({
    page:1,
    limit:20,
    user_id:'',
    game_id:'',
  })
  const typeChange = ()=>{
    getList()
  }
  const getSession = async()=>{
    const loading = Toastloading()
    const res = await ChallengeApi.gameSwitch()
    const { data=[] } = res
    action.SessionList = data
    loading.close()
    getList()
  }
  const getList = async()=>{
    const loading = Toastloading()
    const { playTime, endTime } = action.timeObj
    const res = await ChallengeApi.userDrawList({
      ...listQuery,
      date_st:getTimestamp(playTime,'s'),
      date_ed:getTimestamp(endTime,'s')
    })
    const { data=[] } = res.data || {}
    action.list = data
    loading.close()
  }
  onMounted(() => {
    getSession()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">用户UUID：</div>
          <serachUserid v-model:user_id="listQuery.user_id" />
        </div>
        <div class="labelItem">
          <div class="label">游戏类型：</div>
          <el-select v-model="listQuery.game_id" @change="typeChange" clearable placeholder="请选择类型">
            <el-option
              v-for="item in action.SessionList"
              :label="item.game_name"
              :value="item.game_id"
            />
          </el-select>
        </div>
        <xmDatePicker type="daterange" v-model:timeval="action.timeObj" />
        <div class="labelItem">
          <el-button type="primary" @click="typeChange">查询</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column type="expand">
        <template #default="scope">
          <el-table
          :data="scope.row.logs">
            <el-table-column width="140" prop="i" label="序号" />
            <el-table-column width="180" prop="itemType" label="游戏类型">
              <template #de fault="scope">
                {{ scope.row.itemType == 1?'礼物':'' }}
                {{ scope.row.itemType == 2?'技能':'' }}
              </template>
            </el-table-column>
            <el-table-column min-width="100" prop="rewardGifts" label="礼物奖励">
              <template #default="scope">
                {{ scope.row.rewardGifts.toString() }}
              </template>
            </el-table-column>
            <el-table-column width="180" prop="reward_diamand_num" label="奖励总价值(金豆)" />
          </el-table>
        </template>
      </el-table-column>
      <el-table-column min-width="100" prop="game_name" label="游戏类型" />
      <el-table-column min-width="140" prop="created_at" label="时间">
        <template #default="scope">
          {{ getHMMSS(scope.row.created_at * 1000) }}
        </template>
      </el-table-column>
      <el-table-column min-width="100" prop="uuid" label="UUID" />
      <el-table-column min-width="100" prop="order_id" label="订单id" />
      <el-table-column min-width="100" sortable prop="drawNum" label="挑战次数" />
      <el-table-column min-width="100" sortable prop="reward_diamand_num" label="礼物总价值(钻石)" />
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
  </div>
</template>

<style lang='scss' scoped>
  
</style>